import router from '/src/router/index.js'
import store from '/src/store/index.js'
import { ElMessage } from 'element-plus'
import adminConfig from '/src/_config/admin.config.js'

document.title = adminConfig.title

if (document.body.clientWidth <= 768) {
	store.commit('app/setCollapse', 0)
	store.commit('app/setShowMenu', 0)
}

// 监测窗口大小的变化
window.addEventListener('resize', function () {
	if (document.body.clientWidth <= 768) {
		store.commit('app/setCollapse', 0)
	}
})

// 监测本地存储信息是否人为删改
window.addEventListener('storage', (function () {
	let timer = null
	return function (e) {
		if (timer) return
		store.commit('clearAllInfo')
		if (router.currentRoute.value.name !== 'login') {
			ElMessage({
				message: '本地信息被删改, 请重新登录!',
				type: 'error'
			})
			router.push('/login')
		}
		timer = setTimeout(() => {
			timer = null
		}, 1000)
	}
})())